<template>
  <div class="banner-carousel-container">
    <el-carousel :interval="5000" arrow="always" height="440px">
      <el-carousel-item v-for="(item, index) in banners" :key="index">
        <div 
          class="banner-item" 
          :style="{ backgroundImage: `url(${item.image})` }"
          @click="navigateToBanner(item)"
        >
          <div class="banner-content">
            <h2 class="banner-title">{{ item.title }}</h2>
            <p class="banner-description">{{ item.description }}</p>
            <el-button type="primary" size="large" @click.stop="navigateToBanner(item)">
              {{ item.buttonText }}
            </el-button>
          </div>
        </div>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script setup>
import { computed } from 'vue';
import { useStore } from 'vuex';
import { useRouter } from 'vue-router';

const store = useStore();
const router = useRouter();

// 从 store 获取轮播图数据
const banners = computed(() => store.state.home.banners);

// 处理轮播图点击
const navigateToBanner = (banner) => {
  if (banner.link) {
    if (banner.link.startsWith('http')) {
      window.open(banner.link, '_blank');
    } else {
      router.push(banner.link);
    }
  }
};
</script>

<style lang="scss" scoped>
.banner-carousel-container {
  height: 100%;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
  
  :deep(.el-carousel__container) {
    height: 100%;
  }
  
  .banner-item {
    height: 100%;
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: center;
    padding: 0 50px;
    
    .banner-content {
      max-width: 500px;
      color: #fff;
      text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
      
      .banner-title {
        font-size: 28px;
        margin: 0 0 15px;
      }
      
      .banner-description {
        font-size: 16px;
        margin: 0 0 20px;
        line-height: 1.5;
      }
    }
  }
}
</style> 